#include "WM.h"
#include "WinList.h"
#include <stddef.h>
#include "XBF_Font.h"
#include "IMAGE.h"

extern GUI_FONT        XBF_FontAA32;
extern GUI_CONST_STORAGE GUI_BITMAP bmtest;

extern const unsigned char _acgif[];
extern const unsigned char _actest[]; 

static void cbBackgroundWin(WM_MESSAGE *pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
    static int xpos = 0;
    static int flag = -1;
    static WM_HTIMER hTimer;

    switch(pMsg->MsgId)
    {
        case WM_PAINT:
        {
            //GUI_SetBkColor(0xffffff);
            GUI_Clear();
            //GUI_SetFont(&XBF_FontAA32);
            GUI_SetColor(0xffffff);
            GUI_DispString("Lifesense");
            //GUI_DispStringAt("深圳乐心医疗电子有限公司", xpos, 11);
            //GUI_GIF_Draw(_acgif, 2678, 0, 0);
            //GUI_DrawBitmap(&bmtest, 0, 0);
            
            break;
        }
        
        case WM_TIMER:
        {
            WM_RestartTimer(pMsg->Data.v, 20);
            xpos = xpos + flag * 2;
            if(xpos == -128)
            {
                flag = 1;
            }
            else if(xpos >= 10)
            {
                flag = -1;
            }
            WM_InvalidateWindow(hWin);
            
            break;
        }
        
        case WM_CREATE:
        {
            hTimer = WM_CreateTimer(hWin, 0, 100, 0);
            break;
        }

        default:
            WM_DefaultProc(pMsg);
    }
}

static void cbWin(WM_MESSAGE *pMsg)
{
    switch(pMsg->MsgId)
    {
        case WM_PAINT:
        {
            //GUI_GIF_Draw(_acgif, 2678, 0, 0);
            break;
        }
        default:
            WM_DefaultProc(pMsg);
    }
}


void MainTask(void)
{
    WM_HWIN hWin;
    IMAGE_Handle imgHandle;
    
    GUI_Init();
    //GUI_SetXBF();

    GUI_UC_SetEncodeUTF8();

    WM_SetCallback(WM_HBKWIN, cbBackgroundWin);
    //WM_CreateTimer(WM_HBKWIN, 0, 100, 0);

    //WinMenuCreate(WM_HBKWIN, NULL);
    //hWin = WM_CreateWindowAsChild(0,0,128,64,WM_HBKWIN,WM_CF_SHOW, cbWin, 0);
    //imgHandle = IMAGE_CreateEx(0,0,128,64,hWin,WM_CF_SHOW, IMAGE_CF_MEMDEV|IMAGE_CF_AUTOSIZE, GUI_ID_IMAGE0);
    //IMAGE_SetGIF(imgHandle, _acgif, 2678);
    //IMAGE_SetBitmap(imgHandle, &bmtest);
    //IMAGE_SetBMP(imgHandle, _actest, 1661);
    
    while(1)
    {
        GUI_Delay(10);
    }
}


